package com.neusoft.nep.NEPM.controller;

import com.neusoft.nep.entity.Manager;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;

public class LoginViewControler extends Application {
    @FXML
    BorderPane borderPane;
    @FXML
    private Button logIn;
    @FXML
    private TextField userName;
    @FXML
    private TextField  passWord;
    @FXML
    private ImageView imageView;
    @FXML
    private StackPane stackPane;
    @FXML
    Pane pane;
    @FXML
    private Stage stage;
    public static void main(String[] args) {
        launch(args);
    }
    public  void initialize(){
        Image image=new Image("resource/image/environment.jpg");
        imageView.setImage(image);System.out.println("初始化成功");
        imageView.fitHeightProperty().bind(stackPane.heightProperty());
        imageView.fitWidthProperty().bind(stackPane.widthProperty());
        imageView.setPreserveRatio(false);
        imageView.setSmooth(true);

    }

    public void start(Stage stage) throws Exception {
        FXMLLoader fxmlLoader=new FXMLLoader();
        URL url=getClass().getResource("../view/LogInView.fxml");
        fxmlLoader.setLocation(url);
        Parent root = fxmlLoader.load();
        Scene scene=new Scene(root);
        stage.setScene(scene);
        stage.show();

    }
    @FXML
    public void login() throws IOException {
        Manager manager=new Manager("111","111");
        if (userName.getText().equals(null)){
            System.out.println("用户名不能为空");return;
        }
        if (userName.getText().equals(manager.getUserName())){
            if (passWord.getText().equals(manager.getPassWord())){
                System.out.println("登陆成功");
                FXMLLoader fxmlLoader=new FXMLLoader();
                URL url=getClass().getResource("../view/ManagerUIView.fxml");
                fxmlLoader.setLocation(url);
                Parent root = fxmlLoader.load();
                Scene scene=new Scene(root);
                Stage stage = (Stage) logIn.getScene().getWindow();
                stage.setScene(scene);stage.show();
            }else {
                System.out.println("密码错误或密码为空");
            }
        }else{
            System.out.println("用户名错误");
        }
    }


}
